<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/view/common/common.jsp" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Hiring-所有招聘职位</title>
		<link rel="stylesheet" href="${ctx }/vendor/bootstrap-3.3.7-dist/css/bootstrap.min.css"/>
		<style>
			.container {
				padding-top: 10px;
			}
			
			.panel-body>div {
				float: left;
				width: 25%;
			}
			
			.search {
				margin-bottom: 10px;
				text-align: center;
			}
			
			.search .input {
				display: inline;
				width: 40%;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<c:if test="${empty company && empty talent}">
				<span>
					<a href="${ctx }/companyServlet?command=toLoginUI">企业登录</a> <a href="${ctx }/company_toRegisterUI.action">企业注册</a>
					<span class="text-primary">|</span> 
					<a href="${ctx }/TalentServlet?command=toUserloginUI">求职者登录</a> <a href="${ctx }/TalentServlet?command=toUserRegisterUI">求职者注册</a>
				</span>
			</c:if>
			<c:if test="${not empty company || not empty talent}">
				<span>
					欢迎您，${company.name }${talent.name }！ 
					<c:if test="${not empty company}">
						<a href="${ctx }/CompanyServlet?command=toMainUI">后台管理</a> 
					</c:if>				
					<c:if test="${not empty talent }">
						<a href="${ctx }/TalentServlet?command=toMainUI">后台管理</a> 
					</c:if>
					<a href="${ctx }/CommonServlet?command=logout">退出登录</a>
				</span>
			</c:if>
			<hr>
			<div class="search">
				<form id="queryForm" action="${ctx }/position_listAll.action" method="post">
					<input type="text" class="input form-control" placeholder="请输入职位或公司名称" name="queryStr" value="${queryStr }">
					<button type="submit" class="button btn btn-primary">搜索</button>
				</form>
			</div>
			<c:if test="${empty pageModel.list }">
				<div class="text-center">暂无数据！</div>
			</c:if>
			<c:if test="${not empty pageModel.list }">
				<c:forEach items="${pageModel.list }" var="position" varStatus="vs">
					<div class="panel panel-primary">
				        <div class="panel-heading">
					        <h3 class="panel-title">
					        	${(pageModel.pageNo - 1) * pageModel.pageSize + vs.count }、${position.companyName }&nbsp;&nbsp;“${position.companySlogan }”
					        </h3>
					   </div>
					   <div class="panel-body">
					        <div><a href=""><strong>${position.name }</strong></a></div>
					        <div>￥${position.salary1 }-${position.salary2 }</div>
					        <div>${position.companyAddress }</div>
					        <div><fmt:formatDate value="${position.releaseTime }" pattern="yyyy-MM-dd HH:mm:ss"/></div>
					   </div>
					</div>
				</c:forEach>
				<div class="text-center">
					<!-- 
					每页显示条数
		      			<select class="form-control" style="display:inline; width:auto;" id="pageSizeSelect" onchange="go('${ctx }/position_listAll.action?pageNo=${pageModel.pageNo}')">
		      				<c:forEach items="10,20,30,50" var="pageSize">
		      					<option <c:if test="${pageSize == pageModel.pageSize }">selected</c:if>>${pageSize }</option>	
		      				</c:forEach>
		      			</select>
		      			&nbsp;&nbsp;
		      			<a href="javascript:go('${ctx }/position_listAll.action?pageNo=${pageModel.first}')" class="btn btn-primary">首页</a>
		      			<a href="javascript:go('${ctx }/position_listAll.action?pageNo=${pageModel.pre}')" class="btn btn-primary">上一页</a>
		      			跳转至第
		      			<select class="form-control" style="display:inline; width:auto;" onchange="go('${ctx }/position_listAll.action?pageNo=' + this.value)">
		      				<c:forEach begin="1" end="${pageModel.totalPages }" step="1" var="i">
		      					<option <c:if test="${i == pageModel.pageNo }">selected</c:if>>${i }</option>	
		      				</c:forEach>
		      			</select>
		      			页
		      			<a href="javascript:go('${ctx }/position_listAll.action?pageNo=${pageModel.next}')" class="btn btn-primary">下一页</a>
		      			<a href="javascript:go('${ctx }/position_listAll.action?pageNo=${pageModel.last}')" class="btn btn-primary">尾页</a>
		      			&nbsp;&nbsp;
		      			共${pageModel.totalPages }页，${pageModel.totalRecords }条记录
		      	 	-->
		      	 	
		      	 	<nav aria-label="Page navigation">
					  <ul class="pagination">
					    <li>
					      <a href="javascript:go('${ctx }/position_listAll.action?pageNo=${pageModel.pre}')" aria-label="Previous">
					        <span aria-hidden="true">&laquo;</span>
					      </a>
					    </li>
					    <c:if test="${pageModel.totalPages <= 10}">
					    	<c:set var="begin" value="1"></c:set>
					    	<c:set var="end" value="${pageModel.totalPages}"></c:set>
					    </c:if>
					    <c:if test="${pageModel.totalPages > 10}">
					    	<c:set var="begin" value="${pageModel.pageNo - 5 }"></c:set>
					    	<c:set var="end" value="${pageModel.pageNo + 4 }"></c:set>
					    	<c:if test="${pageModel.pageNo <= 5 }">
						    	<c:set var="begin" value="1"></c:set>
						    	<c:set var="end" value="10"></c:set>
					    	</c:if>
					    	<c:if test="${end > pageModel.totalPages }">
						    	<c:set var="begin" value="${pageModel.totalPages - 10 }"></c:set>
						    	<c:set var="end" value="${pageModel.totalPages }"></c:set>
					    	</c:if>
					    </c:if>
					    <c:forEach begin="${begin }" end="${end }" step="1" var="v">
					    	<li <c:if test="${pageModel.pageNo == v }">class="active"</c:if>><a href="javascript:go('${ctx }/position_listAll.action?pageNo=${v}')">${v }</a></li>
					    </c:forEach>
					    <li>
					      <a href="javascript:go('${ctx }/position_listAll.action?pageNo=${pageModel.next}')" aria-label="Next">
					        <span aria-hidden="true">&raquo;</span>
					      </a>
					    </li>
					  </ul>
					</nav>
				</div>
			</c:if>
	   </div>
	   <script src="${ctx }/vendor/jquery.min.js"></script>
	   <script>
		function go(url) {
			url = url + '&pageSize=' + $('#pageSizeSelect').val();
			$('#queryForm').attr('action', url).submit();
		}
	   </script>
	</body>
</html>